package cn.iocoder.yudao.module.bk.dal.mysql.lwbook;

import java.util.*;
import java.time.LocalDateTime;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.bk.dal.dataobject.lwbook.LwBookDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.bk.controller.admin.lwbook.vo.*;

/**
 * 来往书籍 Mapper
 *
 * @author qy
 */
@Mapper
public interface LwBookMapper extends BaseMapperX<LwBookDO> {

    default PageResult<LwBookDO> selectPage(LwBookPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LwBookDO>()
                .likeIfPresent(LwBookDO::getTitle, reqVO.getTitle())
                .likeIfPresent(LwBookDO::getIsbn, reqVO.getIsbn())
                .likeIfPresent(LwBookDO::getPublisher, reqVO.getPublisher())
                .eqIfPresent(LwBookDO::getApplyStatus, reqVO.getApplyStatus())
                .orderByDesc(LwBookDO::getId));
    }

    /**
     * 查询指定日期范围内的书籍数量
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 书籍数量
     */
    default Long countByCreateTimeBetween(LocalDateTime startTime, LocalDateTime endTime) {
        return selectCount(new LambdaQueryWrapperX<LwBookDO>()
                .between(LwBookDO::getCreateTime, startTime, endTime));
    }

    /**
     * 查询指定日期范围内的书籍数量
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 书籍数量
     */
    default Long countByStoreTimeBetween(LocalDateTime startTime, LocalDateTime endTime) {
        return selectCount(new LambdaQueryWrapperX<LwBookDO>()
                .between(LwBookDO::getStoreTime, startTime, endTime));
    }

}
